package com.iflytek.sort;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class CovidCountBean2 implements WritableComparable<CovidCountBean2> {

    private long cases;//确诊病例数
    private long deaths;//死亡病例数

    public CovidCountBean2() {
    }

    public CovidCountBean2(long cases, long deaths) {
        this.cases = cases;
        this.deaths = deaths;
    }

    public void set(long cases, long deaths) {
        this.cases = cases;
        this.deaths = deaths;
    }

    public long getCases() {
        return cases;
    }

    public void setCases(long cases) {
        this.cases = cases;
    }

    public long getDeaths() {
        return deaths;
    }

    public void setDeaths(long deaths) {
        this.deaths = deaths;
    }

    /**
     *  序列化方法
     */
    @Override
    public void write(DataOutput out) throws IOException {
        out.writeLong(cases);
        out.writeLong(deaths);
    }

    /**
     * 反序列化方法 注意顺序
     */
    @Override
    public void readFields(DataInput in) throws IOException {
        this.cases = in.readLong();
        this.deaths =in.readLong();
    }

    @Override
    public String toString() {
        return  cases +"\t"+ deaths;
    }

    /**
     * 排序比较器  本业务中根据确诊案例数倒序排序
     */
    @Override
    public int compareTo(CovidCountBean2 o) {
        return this.cases - o.getCases()> 0 ? -1:(this.cases - o.getCases() < 0 ? 1 : 0);
        // Long result = this.cases - o.cases;
        // return result.compareTo(o.deaths);
    }
}